<?php /*
	
*/ ?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/adminlogin.js"></script>
<script language="javascript">
function enableRegister(){
	if (document.getElementById("username").focus=true)
		document.getElementById("Submit").disabled = false;
	else
		document.getElementById("Submit").disabled = true;
}


function changeCount()
{
var docF=document.form1;
var str=new String();
str=trim(docF.Information.value);
str=trim_newline(str);
docF.wordcount.value=str.length;
}

function trim_newline(string)
{
return string.replace(/^\s*|\s*$/g, "");
}
</script>
<form name="adminlogin" method="post" action="index.php" >
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="7%">&nbsp;</td>
    <td width="90%">
	
<?php
// Login operation of the admin
if(isset($_REQUEST['actioneded']))
{
	if($_REQUEST['actioneded']=="checkloginadmin")
	{
		$varusername = $_REQUEST['username'];
		$varpassword = md5($_REQUEST['password']);
			
		$login = "SELECT * FROM tbladmin 
						WHERE varadminname = '$varusername' AND varpassword = '$varpassword'";
		$result1 = $obj_db->select($login);
			
		if($result1) {
				$display = $result1[0]['intstatus'];
			if($display=="0") {
				header("location:index.php?msg=lnvalid");
				die();
			} else {
			
				$userid = $result1[0]['intid'];
				$_SESSION['adminuserid'] = $userid;
				$_SESSION['acctype'] = $result1[0]['intstatus'];
				$sql = "SELECT varadminfname FROM tbladmin WHERE intid = '$userid'";
				$result2 = $obj_db->select($sql);
				$result2[0]['varlastname'];
				$_SESSION['msg'] = "Welcome ".$result2[0]['varadminfname'];				
				configvalfetch($obj_db);
				$sql_upd="update tbladmin set ttLastLogginDatetime=NOW() where intid=".$_SESSION['adminuserid'];
				$upd=$obj_db->edit($sql_upd);				
			}
				header("location:index.php");
				die();
		} else {
			header("location:index.php?msg=lnvalid");
			die();
		}
	}
} else {
	if (isset($_SESSION['msg'])) {
		echo $_SESSION['msg'];
	} else {
	?>
		
		<table width="46%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
		  <tr class="bg1">
			<td height="18" colspan="3" align="center">Admin Login... </td>
			</tr>
		  <tr>
			<td align="right">&nbsp;</td>
			<td align="center">&nbsp;</td>
			<td>&nbsp;</td>
		  </tr>
		  <tr>
			<td width="34%" align="right" class="sltimg"><span id="uname">Admin Name </span></td>
			<td width="5%" align="center">:</td>
			<td width="61%"><input name="username" type="text" id="username" maxlength="15" onBlur="this.style.margin = '1px'; this.style.borderWidth = '1px'; this.style.backgroundColor = '#E9F0F5';" onFocus=" this.style.margin = '0'; this.style.borderWidth = '2px'; this.style.backgroundColor = '#FFFFFF'; " /></td>
		  </tr>
		  <tr>
			<td align="right" class="sltimg">Password</td>
			<td align="center">:</td>
			<td><input name="password" type="password" id="password" maxlength="15" /></td>
		  </tr>
		  <tr>
			<td colspan="3" align="center"><a href="forgotpassword.php" class="error" >Forgot Password?</a> </td>
		  </tr>
		  <tr>
			<td colspan="3" align="center" id="uname"><input name="Submit"  style="height:25px;" type="submit" class="btn" value="Admin Login" onClick="return check();" />
			  <input name="actioneded" type="hidden" id="actioneded" value="checkloginadmin" /></td>
			</tr>
		</table>
		<p>
      <?php
	  }
} 
?>
    </p>
    <p>&nbsp; </p></td>
    <td width="3%">&nbsp;</td>
  </tr>
</table>
</form>
<?php include "inc/footer.php";?>
